<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>网站信息</title>
    <link rel="stylesheet" href="${ctxPath}/assets/libs/layui/css/layui.css"/>
    <link rel="stylesheet" href="${ctxPath}/assets/module/admin.css"/>
</head>

<body>
<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-header">网站配置</div>
        <div class="layui-card-body">
            <form class="layui-form model-form">
                <input name="id" type="hidden" value="${webInfo.id}"/>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站名称</label>
                    <div class="layui-input-block">
                        <input name="name" placeholder="请输入网站名称" type="text" class="layui-input" maxlength="20" value="${webInfo.name}"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站标题</label>
                    <div class="layui-input-block">
                        <input name="title" placeholder="请输入网站标题" type="text" class="layui-input" maxlength="30" value="${webInfo.title}"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">网站域名</label>
                    <div class="layui-input-block">
                        <input name="domain" placeholder="请输入网站域名" type="text" class="layui-input" maxlength="50" value="${webInfo.domain}"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">版权信息</label>
                    <div class="layui-input-block">
                        <input name="license" placeholder="请输入版权信息" type="text" class="layui-input" value="${webInfo.license}"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">版本信息</label>
                    <div class="layui-input-block">
                        <input name="version" placeholder="请输入网站域名" type="text" class="layui-input" value="${webInfo.version}"
                               lay-verType="tips" lay-verify="required" required/>
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">登录背景</label>
                    <div class="layui-input-inline">
                        <input name="loginBg" lay-verify="required" id="loginBg" placeholder="图片地址" value="${webInfo.loginBg}" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary" id="LAY_avatarUpload">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <button class="layui-btn layui-btn-primary" id="loginPreview">查看图片</button >
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">锁屏背景</label>
                    <div class="layui-input-inline">
                        <input name="lockBg" lay-verify="required" id="lockBg" placeholder="图片地址" value="${webInfo.lockBg}" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary" id="LockBgUpload">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <button class="layui-btn layui-btn-primary" id="lockPreview">查看图片</button >
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">网站logo</label>
                    <div class="layui-input-inline">
                        <input name="logoImg" lay-verify="required" id="logoImg" placeholder="图片地址" value="${webInfo.logoImg}" class="layui-input">
                    </div>
                    <div class="layui-input-inline layui-btn-container" style="width: auto;">
                        <button type="button" class="layui-btn layui-btn-primary" id="LAY_logoUpload">
                            <i class="layui-icon">&#xe67c;</i>上传图片
                        </button>
                        <button class="layui-btn layui-btn-primary" id="logoPreview">查看图片</button >
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-filter="webInfoSubmit" lay-submit>确认修改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>

</div>

<!-- js部分 -->
<script type="text/javascript" src="${ctxPath}/assets/libs/layui/layui.js"></script>
<script type="text/javascript" src="${ctxPath}/assets/js/common.js"></script>
<script>
    layui.use(['layer', 'form', 'admin', 'upload'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var admin = layui.admin;
        var upload = layui.upload;

        // 表单提交事件
        form.on('submit(webInfoSubmit)', function (data) {
            layer.load(2);
            var url = '/syswebinfo/update';
            $.post(url, data.field, function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    top.layui.admin.closeThisTabs();
                    layer.msg(res.msg, {icon: 1});
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, 'json');
            return false;
        });

        //上传登录背景
        var uploadInst1 = upload.render({
            elem: '#LAY_avatarUpload',
            url: uploadImgUrl(),
            accept: 'images',
            acceptMime: 'image/*',
            choose: function (obj) {
            },
            done: function (res, index, upload) {
                if (res.code!=1){
                    layer.msg(res.msg, {icon: 2});
                } else{
                    layer.msg(res.msg, {icon: 1});
                    var imgurl = res.data.length>0?(imgFileDomain()+res.data[0]):"";
                    $('#loginBg').val(imgurl);
                }
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
            }
        });


        $('#loginPreview').click(function () {
            layer.photos({photos: {title: "查看背景图", data: [{src: $('#loginBg').val()}]}, shade: .01, closeBtn: 1, anim: 5})
            return false;
        });

        //上传锁屏背景
        var uploadInst3 = upload.render({
            elem: '#LockBgUpload',
            url: uploadImgUrl(),
            accept: 'images',
            acceptMime: 'image/*',
            choose: function (obj) {
            },
            done: function (res, index, upload) {
                if (res.code!=1){
                    layer.msg(res.msg, {icon: 2});
                } else{
                    layer.msg(res.msg, {icon: 1});
                    var imgurl = res.data.length>0?(imgFileDomain()+res.data[0]):"";
                    $('#lockBg').val(imgurl);
                }
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
            }
        });


        $('#lockPreview').click(function () {
            layer.photos({photos: {title: "查看背景图", data: [{src: $('#lockBg').val()}]}, shade: .01, closeBtn: 1, anim: 5})
            return false;
        });

        //上传logo
        var uploadInst2 = upload.render({
            elem: '#LAY_logoUpload',
            url: uploadImgUrl(),
            accept: 'images',
            acceptMime: 'image/*',
            choose: function (obj) {
            },
            done: function (res, index, upload) {
                if (res.code!=1){
                    layer.msg(res.msg, {icon: 2});
                } else{
                    layer.msg(res.msg, {icon: 1});
                    var imgurl = res.data.length>0?(imgFileDomain()+res.data[0]):"";
                    $('#logoImg').val(imgurl);
                }
            },
            error: function () {
                layer.msg('上传失败', {icon: 2});
            }
        });

        $('#logoPreview').click(function () {
            layer.photos({photos: {title: "查看背景图", data: [{src: $('#logoImg').val()}]}, shade: .01, closeBtn: 1, anim: 5})
            return false;
        });


    });
</script>


</body>
</html>